/******************************************************/
/* Goblin's Cube - Rubik's cube game for Wii Homebrew */
/* Copyright (C) 2009 Ricardo Bueno Cordeiro          */
/* Licensed under de GNU General Public License v2.0  */
/*   See license_gplv2.txt for detalis                */
/******************************************************/

#ifndef __HIGHSCORE_H_
#define __HIGHSCORE_H_

#include "draw.h"

#define NUM_HIGHSCORES 10
#define TITLE_SIZE 256
#define FOOTER_SIZE 256

#define BUFFER_SIZE 2048

#define LINE_PADDING 10
#define LINE_WIDTH 420
#define LINE_HEIGHT (FONT_SIZE + LINE_PADDING)

class Highscore {
private:
	struct score_t {
		char name[3];
		f32 time;
	};

	struct send_argument_t {
		Highscore *h;
		struct score_t s;
		Highscore *lt;
	};

	s32 mutex_status;
	mutex_t mutex;

	int num;
	struct score_t score[NUM_HIGHSCORES + 1];

	char title[TITLE_SIZE];
	char footer[FOOTER_SIZE];

	static void *load_online_thread_entry(void *t);
	void load_online_thread();

	static void *send_online_thread_entry(void *t);
	void send_online_thread(const char *name, s32 time, Highscore *load_to);

	void set_footer(const char *s);
	int parse_buffer(char *buffer, char *response);
	void parse_response(const char *buffer);
		
public:
	Highscore(const char *title);
	~Highscore();

	void send_online(int score, Highscore *load_to);
	void load_online();
	void load_local();
	void save_local();
	
	int add_score(const char *name, f32 time);
	
	void draw_board(f32 x, f32 y, int naming, int letter);
	
	u8 get_char(int i, int l);
	void set_char(int i, int l, u8 c);
};

#endif
